package com.newegg.bigmap.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import indi.fritz.bigmap.common.Page;
import indi.fritz.bigmap.volme.Engine;
import indi.fritz.bigmap.volme.model.KeyValue;

@Service
public class DatabaseService {

	@Autowired
	Engine engine;
	
	public String get(String key) {
		return engine.read(key);
	}
	
	public long put(String key, String value){
		return engine.write(key, value);
	}
	
	public List<Long> bitch(Map<String, String> datas){
		List<Long> list = new ArrayList<Long>();
		datas.forEach((key,value)->{
			list.add(engine.write(key, value));
		});
		return list;
	}
	
	public String delete(String key){
		String value = engine.delete(key);
		if(value == null){ return null; }
		return value;
	}
	
	public Page<KeyValue> page(long cursor, int pageSize){
		return engine.read(cursor, pageSize);
	}
	
	public long count(){
		return engine.length();
	}
}
